$(document).ready(function() {
	$("#frmComment").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {				
			pcontent: {
				requiredContent		: true,
				minlengthContent	: true
			}
		},
		messages: {	
			pcontent: {
				requiredContent		: content_required,
				minlengthContent	: content_minlength
			}
		},
		errorPlacement: function(label, element) {	
			var id = element.attr('id');	
			label.insertAfter($('#' + id));			
		},
		submitHandler: function(form) {	
			$('#formCmt').hide();
			$('#loading').show();
			var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
			var strContent		= encodeURIComponent(oEditorContent.GetXHTML( true ));	
			var intNewsId 		= $('#pnewsid').val();
			$.getJSON(				
				HOST_VFRIEND + 'comment/ncmtsend?content='+strContent+'&newsid='+intNewsId+'&callback=?',		
				function(response) {					
					if(response['error'] == 0) {						
						showUIMessage(response['msg']);
						$('#nComment').html(response['data']);						
						$('#tcmt').html(response['total']);
						oEditorContent.SetHTML('');
					} else {
						alert(response['msg']);
					}
					$('#loading').hide();
					$('#formCmt').show();
				}
			);
		}
	});
	$.validator.addMethod('requiredContent',function(){
		var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
		var strContent		= stripTags(oEditorContent.GetXHTML( true ),3);		
		if(strContent == '')
			return false;		
		return true;												 
	});
	$.validator.addMethod('minlengthContent',function(){
		var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
		var strContent		= stripTags(oEditorContent.GetXHTML( true ),3);		
		if(strContent != '' && strContent.length < 2)
			return false;		
		return true;												 
	});
});

function addQuote(hexid, commentid, strShort)
{
	var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
	oEditorContent.SetHTML('[quote'+hexid+','+commentid+']'+strShort+'[/quote]');
}
